//
//  ViewController.m
//  01-UIViewHomeWork
//
//  Created by QC.L on 16/7/14.
//  Copyright © 2016年 QC.L. All rights reserved.
//
// 链接: http://www.jianshu.com/p/4c1bda60e90b
#import "ViewController.h"
#import "PassWordViewController.h"
#import "LoginViewController.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
@interface ViewController ()<UITextFieldDelegate>
@property (nonatomic, assign) BOOL isSele;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBarController.tabBar.hidden= YES;
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatLogin];
    self.navigationController.navigationBar.hidden = YES;
   
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(10, 10, 50, 50);
    [btn setTitle:@"返回" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.view addSubview:btn];
    [btn addTarget:self action:@selector(clickLeft:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)creatLogin {
    // 背景
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [imageView setImage:[UIImage imageNamed:@"welcome_2"]];
    [self.view addSubview:imageView];
    // logo
    UIImageView *imageLogo = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.frame.size.width / 3 , self.view.frame.size.height / 8 , 150, 220)];
    [imageLogo setImage:[UIImage imageNamed:@"logo_lagou"]];
    [imageView addSubview:imageLogo];
    
    UITextField *textfieldId = [[UITextField alloc] initWithFrame:CGRectMake(90, self.view.frame.size.height / 2, self.view.frame.size.width - 110, 60)];
    textfieldId.backgroundColor = [UIColor blackColor];
    textfieldId.alpha = 0.2;
    [textfieldId.layer setCornerRadius:10.0];
    textfieldId.textColor = [UIColor lightGrayColor];
    textfieldId.placeholder = @"请输入账号";
    textfieldId.textAlignment = 1;
    [textfieldId setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
    textfieldId.clearsOnBeginEditing = YES;
    textfieldId.textColor = [UIColor whiteColor];
    [self.view addSubview:textfieldId];
    
    UITextField *textfieldPassword = [[UITextField alloc] initWithFrame:CGRectMake(90, self.view.frame.size.height / 2 + 75, self.view.frame.size.width - 110, 60)];
    textfieldPassword.backgroundColor = [UIColor blackColor];
    textfieldPassword.alpha = 0.2;
    textfieldPassword.textColor = [UIColor lightGrayColor];
    textfieldPassword.placeholder = @"请输入密码";
    [textfieldPassword.layer setCornerRadius:10.0];
    [textfieldPassword setValue:[UIColor lightGrayColor] forKeyPath:@"_placeholderLabel.textColor"];
    textfieldPassword.borderStyle = UITextBorderStyleRoundedRect;
    textfieldPassword.clearsOnBeginEditing = YES;
    textfieldPassword.textAlignment = 1;
    textfieldPassword.textColor = [UIColor whiteColor];
    textfieldPassword.secureTextEntry = YES;
    textfieldPassword.keyboardType= UIKeyboardTypeNumberPad;
    textfieldPassword.delegate = self;
    textfieldPassword.keyboardAppearance=UIKeyboardAppearanceAlert;
   
    textfieldPassword.clearsOnBeginEditing = YES;
    [self.view addSubview:textfieldPassword];
    // button
    UIButton *btnId = [UIButton buttonWithType:UIButtonTypeCustom];
    btnId.frame = CGRectMake(20, self.view.frame.size.height / 2, 60, 60);
    btnId.backgroundColor = [UIColor blackColor];
    btnId.alpha = 0.3;
    
    [btnId setImage:[UIImage imageNamed:@"icon_username"] forState:UIControlStateNormal];
      [self.view addSubview:btnId];
    [btnId addTarget:self action:@selector(clickBtnID:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *btnPassword = [UIButton buttonWithType:UIButtonTypeCustom];
    btnPassword.frame = CGRectMake(20, self.view.frame.size.height / 2 + 75, 60, 60);
    btnPassword.backgroundColor = [UIColor blackColor];
    btnPassword.alpha = 0.3;
    [btnPassword setImage:[UIImage imageNamed:@"icon_password"] forState:UIControlStateNormal];
    [self.view addSubview:btnPassword];
    [btnPassword addTarget:self action:@selector(clickBtnPassWord:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *btnLogin = [UIButton buttonWithType:UIButtonTypeSystem];
    btnLogin.frame = CGRectMake(20, self.view.frame.size.height * 0.7 + 10, self.view.frame.size.width - 40, 60);
    [btnLogin setTitle:@"登录" forState:UIControlStateNormal];
    [btnLogin setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [btnLogin.layer setCornerRadius:10.0];
    btnLogin.backgroundColor =  [UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00];
    [imageView addSubview:btnLogin];
    
    UIButton *btnPassWord = [UIButton buttonWithType:UIButtonTypeCustom];
    btnPassWord.frame = CGRectMake(20, 600, 100, 40) ;
    [btnPassWord setTitle:@"忘记密码" forState:UIControlStateNormal];
    [btnPassWord setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [btnPassWord addTarget:self action:@selector(passWordBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnPassWord];
    
    
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeSystem];
    btn2.frame = CGRectMake(self.view.frame.size.width / 3, 610, 100, 40) ;
    [btn2 setTitle:@"现在注册拉钩" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor colorWithRed:0.00 green:0.68 blue:0.53 alpha:1.00] forState:UIControlStateNormal];
    [self.view addSubview:btn2];
    [btn2 addTarget:self action:@selector(loginBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeSystem];
    btn3.frame = CGRectMake(self.view.frame.size.width / 3, 680, 100, 40) ;
    [btn3 setTitle:@"随便逛逛" forState:UIControlStateNormal];
    [btn3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [imageView addSubview:btn3];
    // label
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 660, self.view.frame.size.width - 40, 25)];
    label.text = @"--------------------   or   -------------------";
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont systemFontOfSize:17];
    [imageView addSubview:label];
}

- (void)clickBtnID:(UIButton *)sender {
    if (self.isSele == YES) {
        [sender setImage:[UIImage imageNamed:@"icon_username"] forState:UIControlStateNormal];
    }else{
        [sender setImage:[UIImage imageNamed:@"icon_username_select"] forState:UIControlStateNormal];
    }
    // 取反赋值
    self.isSele = !self.isSele;
}
- (void)clickBtnPassWord:(UIButton *)sender {
    if (self.isSele == YES) {
        [sender setImage:[UIImage imageNamed:@"icon_password"] forState:UIControlStateNormal];
    }else{
        [sender setImage:[UIImage imageNamed:@"icon_password_select"] forState:UIControlStateNormal];
    }
    // 取反赋值
    self.isSele = !self.isSele;
}
- (void)passWordBtn:(UIButton *) sender {
//    PassWordViewController *passWord = [[PassWordViewController alloc] init];
//    [self presentViewController:passWord animated:YES completion:nil];
    [self.navigationController pushViewController:[[PassWordViewController alloc] init] animated:YES];
}
- (void)loginBtn:(UIButton *) sender {
//    LoginViewController *loginVC = [[LoginViewController alloc] init];
//    [self presentViewController:loginVC animated:YES completion:nil];
    [self.navigationController pushViewController:[[LoginViewController alloc] init] animated:YES];
}
- (void)clickLeft:(UIBarButtonItem *)left {
    self.tabBarController.tabBar.hidden = NO;
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
